package com.rjpacket.supernews.app;

import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.rjpacket.supernews.app.adapters.ViewPagerCommonAdapter;
import com.rjpacket.supernews.app.fragments.TutorialFragment;
import com.rjpacket.supernews.app.fragments.TutorialJumpFragment;

import java.util.LinkedList;

//教程页用于第一次进入app导航
public class TutorialActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tutorial);


        //用于显示教程页
        ViewPager viewPager = (ViewPager) findViewById(R.id.tutorial_viewPager);

        LinkedList<Fragment> fragments = new LinkedList<Fragment>();
        //添加教程页显示的Fragment
        TutorialFragment fragment = new TutorialFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(Constants.TUTORIAL_ID, R.layout.item_fragment_tutorial_01);
        fragment.setArguments(bundle);
        fragments.add(fragment);

        fragment = new TutorialFragment();
        bundle = new Bundle();
        bundle.putInt(Constants.TUTORIAL_ID, R.layout.item_fragment_tutorial_02);
        fragment.setArguments(bundle);
        fragments.add(fragment);

        fragments.add(new TutorialJumpFragment());

        ViewPagerCommonAdapter adapter = new ViewPagerCommonAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(adapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_tutorial, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
